import requests
import logging

class Testyk():
    uid=""
    sid=""
    def setup_method(self):
        print("开始")
    def teardown_method(self):
        print("结束")

    def test_dl(self):
        try:
            url="http://10.59.9.18/small/user/v1/login"
            body={"phone":"13811033965","pwd":"123456Aa"}
            # headers={"Content-Type":"application/json"}
            r=requests.post(url=url,json=body)
            Testyk.uid=r.json()['result']['userId']
            Testyk.sid = r.json()['result']['sessionId']
            print("登录成功",r.json())
            logging.info(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200

    # 输入正确的信息，新增地址成功
    def test_Address1(self):
        try:
            url="http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
            body={"realName":"小米","phone":"15138529806","address":"北京 海淀区 八维","zipCode":"101010"}
            headers={"userId":str(Testyk.uid),"sessionId":str(Testyk.sid)}
            r=requests.post(url=url,data=body,headers=headers)
            print("添加成功",r.json())
            logging.info(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
# 邮政编码错误，新增地址失败
    def test_Address2(self):
        try:
            url="http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
            body={"realName":"小米","phone":"15138529806","address":"北京 海淀区 八维","zipCode":"125"}
            headers={"userId":str(Testyk.uid),"sessionId":str(Testyk.sid)}
            r=requests.post(url=url,data=body,headers=headers)
            print("邮政编码错误",r.json())
            logging.info(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200

# 手机号格式错误，新增地址失败
    def test_Address3(self):
        try:
            url="http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
            body={"realName":"小米","phone":"151385296","address":"北京 海淀区 八维","zipCode":"101010"}
            headers={"userId":str(Testyk.uid),"sessionId":str(Testyk.sid)}
            r=requests.post(url=url,data=body,headers=headers)
            print("手机号格式错误",r.json())
            logging.info(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200

# 邮政编码为空，新增地址失败
    def test_Address4(self):
        try:
            url="http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
            body={"realName":"小米","phone":"15138529806","address":"北京 海淀区 八维","zipCode":""}
            headers={"userId":str(Testyk.uid),"sessionId":str(Testyk.sid)}
            r=requests.post(url=url,data=body,headers=headers)
            print("邮政编码为空",r.json())
            logging.info(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
# 用户名为空，新增地址失败
    def test_Address5(self):
        try:
            url="http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
            body={"realName":"","phone":"15138529806","address":"北京 海淀区 八维","zipCode":"101010"}
            headers={"userId":str(Testyk.uid),"sessionId":str(Testyk.sid)}
            r=requests.post(url=url,data=body,headers=headers)
            print("用户名为空",r.json())
            logging.info(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200





